<?php

namespace app\admin\model\member;

use app\admin\model\BaseMode;
use app\admin\model\shareholder\ShareholderModel;
use think\exception\ValidateException;

class Level extends BaseMode
{



    public function getLevelAttr($value): string
    {
        $shareholder=config('view.shareholder_level');
//        $member=config('view.member_level');
//
//        $level=array_merge($member,$shareholder);
//
//        $res=array_values($level);
        return $shareholder[$value];
    }

    public function getTypeAttr($value): string
    {
        $Type=[1=>'会员',2=>'联创'];

        return $Type[$value];
    }


    public static function getList(){

        $where=[];
        $store_json=session('store_id');
        $where[]=['store_id','in',$store_json];
        $where[]=['type','=',2];
        return  (new Level)->where($where)->select();
    }


    public static function insertLevel($add){
        try {
            $add['store_id']=session('store_id');
            self::create($add);
            return array(
                'code' => 200,
                'msg' => '成功!',

            );

            // dump($result);die;

        } catch (ValidateException $e) {
            // 验证失败 输出错误信息
            return $e->getError();
        }

    }

    public static function modifyLevel($add)
    {
        try {
            $result = self::where(['id' => input('id')])->save($add);

            if (!empty($result)) {
                return array(
                    'code' => 200,
                    'msg' => '成功!',

                );
            } else {
                return array(
                    'code' => 40002,
                    'msg' => '成功!',
                );
            }

        } catch (ValidateException $e) {
            // 验证失败 输出错误信息

            return $e->getError();
        }
    }



}